﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Module.Core.Common;
using Module.Common.Models;
using Module.Core.BusinessLogic;

using Module.Core.EntitiesInfo;
using Module.Core.LoginSystem.Commons.Framwork;
namespace Web.Cms.AjaxCP
{
    public partial class PagingAjaxMember : System.Web.UI.UserControl
    {
        
        static int totalPage;
        
        CHRTList<MemberInfo> ListFullMember = new CHRTList<MemberInfo>();        
        CHRTList<MemberInfo> SubListmember = new CHRTList<MemberInfo>();
        static int fromNumber = 0;
        static int toNumber;
        static int cPage = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            ListFullMember = MemberBL.GetParentLeveMemberFull("25479");
            totalPage = (int)Math.Ceiling((double)ListFullMember.Count / 2);
            
            if (!IsPostBack)
            {
                if (totalPage < 1)
                {

                    for (int i = fromNumber; i < ListFullMember.Count; i++)
                    {
                        SubListmember.Add(ListFullMember[i]);
                    }

                }
                else
                {
                    for (int i = 0; i < 2; i++)
                    {
                        SubListmember.Add(ListFullMember[i]);                                                
                    }
                   
                }
                LoadData();
                
            }

        }
        public void LoadData()
        {
            DataList1.DataSource = SubListmember;
            DataList1.DataBind();
        }
        protected void BtnForward_Click(object sender, EventArgs e)
        {
            totalPage = (int)Math.Ceiling((double)ListFullMember.Count / 2);
          
                cPage += 1;
                fromNumber = cPage * 2;
                toNumber = fromNumber + 2;              
                    if (toNumber > ListFullMember.Count)
                    {
                        for (int i = fromNumber; i < ListFullMember.Count; i++)
                        { SubListmember.Add(ListFullMember[i]); }
                        cPage = cPage - 1;
                     
                    }
                    if (toNumber < ListFullMember.Count)
                    {
                        for (int i = fromNumber; i < toNumber; i++)
                        { SubListmember.Add(ListFullMember[i]); }                                              
                    }
               
            LoadData();

        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            if (cPage > 0)
            {
                cPage -= 1;
                 totalPage = (int)Math.Ceiling((double)ListFullMember.Count / 2);
              fromNumber = cPage * 2;
                 toNumber = fromNumber + 2;
                
                     for (int i = fromNumber; i < toNumber; i++)
                     { SubListmember.Add(ListFullMember[i]); }

                 }
                 else
                 {
                     for (int i = 0; i < 2; i++)
                     { SubListmember.Add(ListFullMember[i]); }
                 }
                 LoadData();
           
        }

        protected void bntBack_Click(object sender, EventArgs e)
        {
            cPage = 0;
            fromNumber = 0;
             for (int i = 0; i < 2; i++)
                {
                    SubListmember.Add(ListFullMember[i]);

                }

            
            LoadData();
        }

        protected void btnSeach_Click(object sender, EventArgs e)
        {
            ListFullMember = MemberBL.GetParentLeveMemberFull_Search("29929", TextBox1.Text);
            LoadData();
        }

        protected void BtnEnd_Click(object sender, EventArgs e)
        {
            totalPage = (int)Math.Ceiling((double)ListFullMember.Count / 2);
            cPage = totalPage;
            fromNumber = (cPage - 1) * 2;
            toNumber = fromNumber + 5;
            cPage -= 1;
            if(ListFullMember.Count < toNumber)
            {
                for (int i = fromNumber; i < ListFullMember.Count; i++)         
                {
                    SubListmember.Add(ListFullMember[i]);
                }
             }
            else
            {
                for (int i = fromNumber; i < toNumber; i++)
                {
                    SubListmember.Add(ListFullMember[i]);
                }
            }

            LoadData();


               }
       
    }
}